import request from '@/utils/request'
// 添加数据采集配置
export const addDataCollectConfig = (data) => {
  return request.post('/dataCollectConfig/add', data)
}

// 根据ID查询数据采集配置
export const getDataCollectConfigById = (id) => {
  return request.get(`/dataCollectConfig/select/${id}`, id)
}

// 修改数据采集配置
export const updateDataCollectConfig = (data) => {
  return request.put('/dataCollectConfig/update', data)
}

// 删除数据采集配置
export const deleteDataCollectConfig = (id) => {
  return request.delete(`/dataCollectConfig/delete/${id}`, id)
}

// 数据采集配置列表查询
export const getDataCollectConfigList = (params) => {
  return request.get('/dataCollectConfig/list', params)
}

// 根据数据源ID获取采集配置列表
export const getConfigsByDataSourceId = (dataSourceId) => {
  return request.get(`/dataCollectConfig/selectByDataSourceId/${dataSourceId}`)
}

// 数据转换测试
export const testDataTransform = (collectConfigId, data) => {
  return request.post('/dataTransformRule/transform', {
    params: {
      collectConfigId
    }
  }, data)
}

// ============ 元数据管理相关API ============

// 刷新元数据
export function refreshMetadata (dataSourceId) {
  return request({
    url: `/dataCollectConfig/refreshMetadata/${dataSourceId}`,
    method: 'post'
  })
}

// 获取数据源的表列表
export function getTableList (dataSourceId) {
  return request({
    url: `/dataCollectConfig/tables/${dataSourceId}`,
    method: 'get'
  })
}

// 获取表的字段信息
export function getColumnList (params) {
  return request({
    url: '/dataCollectConfig/columns',
    method: 'get',
    params
  })
}

// ============ 数据预览相关API ============

// 数据预览
export function previewData (data) {
  return request({
    url: '/dataCollectConfig/previewData',
    method: 'post',
    data
  })
}

// 统计记录数
export function countRecords (params) {
  return request({
    url: '/dataCollectConfig/countRecords',
    method: 'get',
    params
  })
}
